"use strict";
const common_vendor = require("../../common/vendor.js");
const utils_api = require("../../utils/api.js");
if (!Array) {
  const _component_AI = common_vendor.resolveComponent("AI");
  _component_AI();
}
const _sfc_main = {
  __name: "course",
  setup(__props) {
    const searchParams = common_vendor.reactive({
      searchText: "",
      current: 1,
      pageSize: 10
    });
    const courseList = common_vendor.ref([]);
    const loading = common_vendor.ref(false);
    const hasMore = common_vendor.ref(true);
    const isRefreshing = common_vendor.ref(false);
    const statusBarHeight = common_vendor.ref(0);
    common_vendor.onMounted(() => {
      const systemInfo = common_vendor.index.getSystemInfoSync();
      statusBarHeight.value = systemInfo.statusBarHeight;
      loadCourseList();
    });
    const loadCourseList = async (isRefresh = false) => {
      if (loading.value)
        return;
      loading.value = true;
      try {
        const res = await utils_api.courseApi.getCourseList(searchParams);
        console.log("课程数据:", res.data);
        if (isRefresh) {
          courseList.value = res.data.records || [];
        } else {
          courseList.value = [...courseList.value, ...res.data.records || []];
        }
        hasMore.value = courseList.value.length < (res.data.total || 0);
        if (!isRefresh && hasMore.value) {
          searchParams.current++;
        }
      } catch (error) {
        console.error("加载课程列表失败:", error);
        common_vendor.index.showToast({
          title: "加载失败",
          icon: "none"
        });
      } finally {
        loading.value = false;
        isRefreshing.value = false;
      }
    };
    const handleSearch = () => {
      searchParams.current = 1;
      loadCourseList(true);
    };
    const refresh = () => {
      isRefreshing.value = true;
      searchParams.current = 1;
      loadCourseList(true);
    };
    const loadMore = () => {
      if (!hasMore.value || loading.value)
        return;
      loadCourseList();
    };
    const getTagType = (course) => {
      if (!course)
        return "recommend";
      if (course.price === 0)
        return "free";
      if ((course.studentCount || course.totalNum || 0) > 1e3)
        return "hot";
      return "recommend";
    };
    const getTagText = (course) => {
      if (!course)
        return "推荐";
      if (course.price === 0)
        return "免费";
      if ((course.studentCount || course.totalNum || 0) > 1e3)
        return "热门";
      return "推荐";
    };
    const goToCourseDetail = (id) => {
      common_vendor.index.navigateTo({
        url: `/pages/course/detail?id=${id}`
      });
    };
    const goToRecommend = () => {
      common_vendor.index.navigateTo({
        url: "/pages/course/recommend"
      });
    };
    return (_ctx, _cache) => {
      return common_vendor.e({
        a: common_vendor.o(handleSearch),
        b: searchParams.searchText,
        c: common_vendor.o(($event) => searchParams.searchText = $event.detail.value),
        d: common_vendor.o(goToRecommend),
        e: common_vendor.f(courseList.value, (course, k0, i0) => {
          return {
            a: course.image || course.image || "/static/course/default.jpg",
            b: common_vendor.t(course.title || course.name),
            c: common_vendor.t(course.studentCount || course.totalNum || 0),
            d: common_vendor.t(course.price > 0 ? `¥${course.price}` : "免费"),
            e: common_vendor.t(getTagText(course)),
            f: common_vendor.n(getTagType(course)),
            g: course.id,
            h: common_vendor.o(($event) => goToCourseDetail(course.id), course.id)
          };
        }),
        f: loading.value
      }, loading.value ? {} : {}, {
        g: !hasMore.value && !loading.value
      }, !hasMore.value && !loading.value ? {} : {}, {
        h: common_vendor.o(loadMore),
        i: common_vendor.o(refresh),
        j: isRefreshing.value
      });
    };
  }
};
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-ffd98509"]]);
wx.createPage(MiniProgramPage);
